package com.db.aggregation;

import com.db.protocol.message.ReportMessage;

import java.util.List;

/**
 * @author nulls.narik
 */
public abstract class AbstractAggregation {

    private final Object monitor = new Object();

    public void aggregate(List<ReportMessage> messages) {
        synchronized (monitor) {
            clear();
            for (ReportMessage message : messages) {
                add(message);
            }
        }
    }

    protected abstract void clear();

    protected abstract void add(ReportMessage message);

    protected abstract List<ReportMessage> getList();

    public List<ReportMessage> getAll() {
        synchronized (monitor) {
            return getList();
        }
    }

}
